package com.xstar.game.gameoflife;

import java.awt.*;

import static com.xstar.game.gameoflife.Main.cellGroup;

public class GameView extends Canvas {

    public final int width;

    public GameView(int width) {
        this.width = width;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        g.setColor(Color.getHSBColor(0.1f, 0, 0.9f));
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.WHITE);
        for (int h = 0; h < cellGroup.height; h++) {
            for (int w = 0; w < cellGroup.width; w++) {
                g.fillRect(w * width + w, h * width + h, width, width);
            }
        }

        g.setColor(Color.BLACK);
        for (int h = 0; h < cellGroup.height; h++) {
            for (int w = 0; w < cellGroup.width; w++) {
                if (cellGroup.getCell(w, h) == 1)
                    g.fillRect(w * width + w, h * width + h, width, width);
            }
        }
    }
}
